#include "shader_mgr.h"

using std::string;

CShaderManager &CShaderManager::GetInstance()
{
    static CShaderManager instance;
    return instance;
}

CShaderManager::~CShaderManager()
{
    for (auto &iter : m_mapShaders)
        iter.second->DeleteShader();
}

CShader *CShaderManager::CreateNewShader(const string &name)
{
    auto shader = std::make_shared<CShader>();
    auto iter = m_mapShaders.emplace(name, shader);
    return iter.first->second.get();
}

CShader *CShaderManager::GetShader(const string &name)
{

    auto iter = m_mapShaders.find(name);
    if (iter == m_mapShaders.end())
    {
        WARN("Not found such shader:: %s", name.c_str());
        return nullptr;
    }
    else
        return iter->second.get();
}